package com.gitee.feizns.quickstart.ding.talk.api.top.api.role;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRoleGetroleRequest;
import com.dingtalk.api.response.OapiRoleGetroleResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 获取角色详情（/topapi/role/getrole）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/queries-role-details">获取角色详情（/topapi/role/getrole）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/queries-role-details">服务端API > 通讯录管理 > 角色管理 > 获取角色详情</a>
 * @author feizns
 * @since 2025/3/24
 */
public class GetRole {

    /**
     * 执行
     * @param accessToken 访问令牌
     * @param roleId 角色编号
     * @return {@link OapiRoleGetroleResponse.OpenRole }
     */
    @SneakyThrows
    public static OapiRoleGetroleResponse.OpenRole execute(String accessToken, Long roleId) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/getrole");
        OapiRoleGetroleRequest req = new OapiRoleGetroleRequest();
        req.setRoleId(roleId);
        OapiRoleGetroleResponse rsp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(rsp).getRole();
    }

}
